package lee.vioson.remotedata.repositories

import android.content.Context
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import lee.vioson.remotedata.bean.AppConfig
import lee.vioson.remotedata.manager.AppConfigManager
import lee.vioson.remotedata.utils.body

/**
 *Author:viosonlee
 *Date:2023/6/1
 *DESCRIPTION:
 */
class InitRepositoryImpl(
    private val context: Context,
    private val api: lee.vioson.remotedata.ApiServices
) : InitRepository,
    BaseRepository() {

    override fun initData(uniqueId: String): Flow<AppConfig> = flow {
        val value = handleNotEmptyResponse(api.init(mapOf("uniqueId" to uniqueId).body))
        emit(value)
        AppConfigManager.INTANCE.saveInitAppConfig(context, value)
    }
}